<?php
/**
 * Created by PhpStorm.
 * User: xiandanjia
 * Date: 2018/10/30
 * Time: 下午 3:36
 */

namespace App\Components;

use Swoft\Bean\Annotation\Inject;


/**
 * 定义json返回结构
 * Class JsonCode
 * @package App\Components
 */
class JsonCode
{
    /**
     * 成功返回结构
     * @param array $data
     * @param string $msg
     */
    public static function Code200($data=[],$msg=''){
        $json['data'] = $data;
        $json['code'] = 200;
        $json['msg'] = $msg??"操作成功";
        return $json;
    }

    /**
     * 失败返回结构
     * @param string $msg
     * @param array $data
     */
    public static function Code400($msg='',$data=[]){
        $json['data'] = $data;
        $json['code'] = 400;
        $json['msg'] = $msg??"操作失败";
        return $json;
    }

    /**
     * 鉴权失败
     * @param string $msg
     * @param array $data
     * @return mixed
     */
    public static function Code300($msg='',$data=[]){
        $json['data'] = $data;
        $json['code'] = 300;
        $json['msg'] = $msg??"鉴权失败";
        return $json;
    }

}